package vista.control;

import controlador.control.GestorControl;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.swing.JOptionPane;
import modelo.Cotizacion;
import modelo.Ejecucion;
import modelo.PedidoObra;
import modelo.Planificacion;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import util.SwingPanel;
import vista.comer.pantallaConsultarObra;
import vista.control.graficos.GraficoAlquileresComprasControlObra;
import vista.control.graficos.GraficoGastosVariosControlObra;
import vista.control.graficos.GraficoHerramientasControlObra;
import vista.control.graficos.GraficoMontosControlObra;
import vista.control.graficos.GraficoTortaRecursosCotizacion;
import vista.control.graficos.GraficoTortaRecursosEjecucion;

/**
 *
 * @author Administrador
 */
public class VentanaControl extends javax.swing.JInternalFrame {

    private GestorControl gestor;
    public static final String MENSAJE_NO_ESTA_COTIZADO = "No está Cotizado";
    public static final String MENSAJE_NO_ESTA_PLANIFICADO = "No está Planificado";
    public static final String MENSAJE_NO_ESTA_EJECUTADO = "No está Ejecutado";

    /**
     * Creates new form VentanaControl
     */
    public VentanaControl(int idPedidoObra) {
        gestor = new GestorControl(idPedidoObra);
        initComponents();
        initDatosObra();
        initEstados();
        initGraficos();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        lblNombreObra = new javax.swing.JLabel();
        lblNombreClienteObra = new javax.swing.JLabel();
        btnVerDatosObra = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        lblNumeroObra = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        lblEstadoPedidoObra = new javax.swing.JLabel();
        lblEstadoCotizacion = new javax.swing.JLabel();
        lblEstadoPlanificacion = new javax.swing.JLabel();
        lblEstadoEjecucion = new javax.swing.JLabel();
        btnCerrar = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel5 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        panelGraficoControlMontos = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel4 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        panelGraficoHerramientas = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        panelGraficoGastosVarios = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        panelGraficoAlquileresCompras = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jPanel7 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        panelGraficoTortaCotizacion = new javax.swing.JPanel();
        jLabel17 = new javax.swing.JLabel();
        panelGraficoTortaEjecucion = new javax.swing.JPanel();
        jPanel13 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jPanel18 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        btnEmitir = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Control de la Obra");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos de la Obra: "));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Nombre:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Cliente:");

        lblNombreObra.setText("Montaje Horno Galletitas .................................................................................");

        lblNombreClienteObra.setText("ARCOR S.A - Planta San Luis .........................................................................");

        btnVerDatosObra.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/iconos/var/16x16/search.png"))); // NOI18N
        btnVerDatosObra.setText("Ver datos de la Obra");
        btnVerDatosObra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVerDatosObraActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Número:");

        lblNumeroObra.setText("1 .................................................................................");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnVerDatosObra, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblNumeroObra, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblNombreClienteObra, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)
                            .addComponent(lblNombreObra, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(lblNumeroObra))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lblNombreObra))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNombreClienteObra)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnVerDatosObra))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Estado de la Obra"));

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("Pedido de Obra:");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setText("Cotización: ");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel7.setText("Planificación: ");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel8.setText("Lanzamiento y Ejecución:");

        lblEstadoPedidoObra.setBackground(new java.awt.Color(153, 255, 153));
        lblEstadoPedidoObra.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblEstadoPedidoObra.setText("Aceptado");
        lblEstadoPedidoObra.setOpaque(true);

        lblEstadoCotizacion.setBackground(new java.awt.Color(153, 255, 153));
        lblEstadoCotizacion.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblEstadoCotizacion.setText("Cotizado (Rev:2)");
        lblEstadoCotizacion.setOpaque(true);

        lblEstadoPlanificacion.setBackground(new java.awt.Color(255, 204, 102));
        lblEstadoPlanificacion.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblEstadoPlanificacion.setText("Planificando");
        lblEstadoPlanificacion.setOpaque(true);

        lblEstadoEjecucion.setBackground(new java.awt.Color(204, 204, 204));
        lblEstadoEjecucion.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblEstadoEjecucion.setText("No Lanzado o ejecutado");
        lblEstadoEjecucion.setOpaque(true);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblEstadoCotizacion, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblEstadoPedidoObra, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblEstadoPlanificacion, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblEstadoEjecucion, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEstadoPedidoObra, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(lblEstadoCotizacion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(lblEstadoPlanificacion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(lblEstadoEjecucion)))
        );

        btnCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/iconos/var/16x16/block.png"))); // NOI18N
        btnCerrar.setText("Cerrar");
        btnCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarActionPerformed(evt);
            }
        });

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel12.setText("Montos Cotizados Vs. Planificados Vs. Ejecutados:");

        panelGraficoControlMontos.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, 573, Short.MAX_VALUE)
                    .addComponent(panelGraficoControlMontos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelGraficoControlMontos, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Montos", jPanel5);

        jLabel13.setText("<HTML>Uso de <b>Herramientas</b> Cotizadas Vs. Planificadas Vs. Ejecutadas");

        panelGraficoHerramientas.setLayout(new java.awt.BorderLayout());

        jLabel14.setText("<HTML><b>Gastos Varios</b> Cotizados Vs. Ejecutados.");

        panelGraficoGastosVarios.setLayout(new java.awt.BorderLayout());

        jLabel15.setText("<HTML>Uso de <b>Alquileres/Compras</b> Cotizados Vs. Planificados Vs. Ejecutados");

        panelGraficoAlquileresCompras.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, 563, Short.MAX_VALUE)
                        .addGap(18, 18, 18))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(panelGraficoAlquileresCompras, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel15, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(panelGraficoHerramientas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(panelGraficoGastosVarios, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap())))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelGraficoHerramientas, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelGraficoGastosVarios, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelGraficoAlquileresCompras, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jScrollPane1.setViewportView(jPanel4);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Recursos", jPanel6);

        jLabel16.setText("<HTML>Contribución de cada 'Tipo de Recurso' al monto total <b>Cotizado</b>");

        panelGraficoTortaCotizacion.setLayout(new java.awt.BorderLayout());

        jLabel17.setText("<HTML>Contribución de cada 'Tipo de Recurso' al monto total <b>Ejecutado</b>");

        panelGraficoTortaEjecucion.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel16)
                    .addComponent(panelGraficoTortaCotizacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, 571, Short.MAX_VALUE)
                    .addComponent(panelGraficoTortaEjecucion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelGraficoTortaCotizacion, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelGraficoTortaEjecucion, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE)
                .addContainerGap())
        );

        jScrollPane2.setViewportView(jPanel7);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Cotización Vs. Ejecución", jPanel3);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setText("Control de la Obra:");

        jLabel9.setText("<HTML>El objetivo de éste módulo es brindar al usuario información estadística y retrospectiva sobre la obra completa, comparando cada una de las etapas con lo que sucedió realmente, estos informes permiten que el usuario mejore sus cotizaciones y planificaciones y que cuente con información histórica de todas las obras que realizó para usar como referencia.");

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/workflow/Workflow-Control.png"))); // NOI18N

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 573, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addContainerGap(70, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("<HTML><span color='002EB8'><b>Ayuda?</b></span>", jPanel13);

        jPanel18.setBorder(javax.swing.BorderFactory.createTitledBorder("Emitir Informe"));

        jLabel11.setText("Emitir un informe completo para el análisis y control de la Obra.");

        btnEmitir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/iconos/var/16x16/print.png"))); // NOI18N
        btnEmitir.setText("Emitir");
        btnEmitir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEmitirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel18Layout = new javax.swing.GroupLayout(jPanel18);
        jPanel18.setLayout(jPanel18Layout);
        jPanel18Layout.setHorizontalGroup(
            jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel18Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnEmitir))
        );
        jPanel18Layout.setVerticalGroup(
            jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel11)
                .addComponent(btnEmitir))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnCerrar))
                    .addComponent(jPanel18, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel18, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCerrar)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnVerDatosObraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerDatosObraActionPerformed
        pantallaConsultarObra win = new pantallaConsultarObra(gestor.getIDObra());
        SwingPanel.getInstance().addWindow(win);
        win.setVisible(true);
    }//GEN-LAST:event_btnVerDatosObraActionPerformed

    private void btnEmitirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEmitirActionPerformed
        emitirInforme();
    }//GEN-LAST:event_btnEmitirActionPerformed

    private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCerrarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton btnEmitir;
    private javax.swing.JButton btnVerDatosObra;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lblEstadoCotizacion;
    private javax.swing.JLabel lblEstadoEjecucion;
    private javax.swing.JLabel lblEstadoPedidoObra;
    private javax.swing.JLabel lblEstadoPlanificacion;
    private javax.swing.JLabel lblNombreClienteObra;
    private javax.swing.JLabel lblNombreObra;
    private javax.swing.JLabel lblNumeroObra;
    private javax.swing.JPanel panelGraficoAlquileresCompras;
    private javax.swing.JPanel panelGraficoControlMontos;
    private javax.swing.JPanel panelGraficoGastosVarios;
    private javax.swing.JPanel panelGraficoHerramientas;
    private javax.swing.JPanel panelGraficoTortaCotizacion;
    private javax.swing.JPanel panelGraficoTortaEjecucion;
    // End of variables declaration//GEN-END:variables

    /**
     * Carga los datos que son comunes a todos los informes de planificacion
     *
     * @param params
     */
    private void cargarDatosCabecera(HashMap<String, Object> params) {
        /*params.put(InformeDePlanificacion.PARAM_PLAN_NRO,this.eje.getNroCotizacionPlanificada());
            
         gestorBDvarios utils = new gestorBDvarios();
         EmpresaCliente ec = utils.buscarEmpresaCliente(this.obra.getPlanta());

         if(ec==null)
         {
         params.put(InformeDePlanificacion.PARAM_PLAN_EMPRESA,"");
         }
         else
         {
         params.put(InformeDePlanificacion.PARAM_PLAN_EMPRESA,ec.toString());
         }
         if(this.obra.getPlanta()!=null)
         {
         params.put(InformeDePlanificacion.PARAM_PLAN_PLANTA,this.obra.getPlanta().toString());
         }
         else
         {
         params.put(InformeDePlanificacion.PARAM_PLAN_PLANTA,"");
         }
        
         params.put(InformeDePlanificacion.PARAM_PLAN_OBRA,this.obra.getNombre());
        
         params.put(InformeDePlanificacion.PARAM_PLAN_FINICIO,FechaUtil.getFecha(this.eje.getFechaInicio()));
        
         params.put(InformeDePlanificacion.PARAM_PLAN_FFIN,FechaUtil.getFecha(this.eje.getFechaInicio()));*/
    }

    /**
     * Busca y llena los datos generales de la obra
     */
    private void initDatosObra() {
        // Número
        String numero = gestor.getNumeroObra();
        lblNumeroObra.setText(numero);
        // Nombre
        String nombre = gestor.getNombreObra();
        lblNombreObra.setText(nombre);
        lblNombreObra.setToolTipText(nombre);
        // Cliente
        String cliente = gestor.getNombreClienteObra();
        lblNombreClienteObra.setText(cliente);
        lblNombreClienteObra.setToolTipText(cliente);
    }

    /**
     * Carga los estados y sus colores
     */
    private void initEstados() {
        initEstadoPedidoObra();
        initEstadoCotizacion();
        initEstadoPlanificacion();
        initEstadoEjecucion();
    }

    private void initEstadoPedidoObra() {
        String estado = gestor.getEstadoPedidoObra();
        lblEstadoPedidoObra.setText(estado);

        // Cambio el Color
        if (estado.equals(PedidoObra.ESTADO_CANCELADO)) {
            lblEstadoPedidoObra.setBackground(new Color(229, 184, 183));
        }
        if (estado.equals(PedidoObra.ESTADO_EN_EJECUCION)) {
            lblEstadoPedidoObra.setBackground(new Color(196, 188, 150));
        }
        if (estado.equals(PedidoObra.ESTADO_PLANIFICADO)) {
            lblEstadoPedidoObra.setBackground(new Color(196, 188, 150));
        }
        if (estado.equals(PedidoObra.ESTADO_COTIZADO)) {
            lblEstadoPedidoObra.setBackground(new Color(196, 188, 150));
        }
        if (estado.equals(PedidoObra.ESTADO_SOLICITADO)) {
            lblEstadoPedidoObra.setBackground(new Color(132, 230, 147));
        }

    }

    private void initEstadoCotizacion() {
        String estado = gestor.getEstadoCotizacionObra();
        lblEstadoCotizacion.setText(estado);

        // Cambio el Color
        if (estado.equals(Cotizacion.ESTADO_ACEPTADO)) {
            lblEstadoCotizacion.setBackground(new Color(214, 227, 188));
        }
        if (estado.equals(Cotizacion.ESTADO_CANCELADO)) {
            lblEstadoCotizacion.setBackground(new Color(229, 184, 183));
        }
        if (estado.equals(Cotizacion.ESTADO_EN_CREACION)) {
            lblEstadoCotizacion.setBackground(new Color(196, 188, 150));
        }
        if (estado.equals(Cotizacion.ESTADO_PENDIENTE_ACEPTACION)) {
            lblEstadoCotizacion.setBackground(new Color(184, 204, 240));
        }
        if (estado.equals(Cotizacion.ESTADO_RECHAZADO)) {
            lblEstadoCotizacion.setBackground(new Color(224, 184, 183));
        }

        if (estado.equals(VentanaControl.MENSAJE_NO_ESTA_COTIZADO)) {
            lblEstadoCotizacion.setBackground(new Color(204, 204, 204));
        }
    }

    private void initEstadoPlanificacion() {
        String estado = gestor.getEstadoPlanificacionObra();
        lblEstadoPlanificacion.setText(estado);

        if (estado.equals(Planificacion.ESTADO_CREADA)) {
            lblEstadoPlanificacion.setBackground(new Color(214, 227, 188));
        }
        if (estado.equals(Planificacion.ESTADO_CANCELADA)) {
            lblEstadoPlanificacion.setBackground(new Color(229, 184, 183));
        }
        if (estado.equals(Planificacion.ESTADO_FINALIZADA)) {
            lblEstadoPlanificacion.setBackground(new Color(184, 204, 240));
        }

        if (estado.equals(VentanaControl.MENSAJE_NO_ESTA_PLANIFICADO)) {
            lblEstadoPlanificacion.setBackground(new Color(204, 204, 204));
        }

    }

    private void initEstadoEjecucion() {
        String estado = gestor.getEstadoEjecucionObra();
        lblEstadoEjecucion.setText(estado);

        if (estado.equals(Ejecucion.ESTADO_CREADA)) {
            lblEstadoEjecucion.setBackground(new Color(184, 204, 240));
        }
        if (estado.equals(Ejecucion.ESTADO_CANCELADA)) {
            lblEstadoEjecucion.setBackground(new Color(229, 184, 183));
        }
        if (estado.equals(Ejecucion.ESTADO_FINALIZADA)) {
            lblEstadoEjecucion.setBackground(new Color(204, 255, 153));
        }

        if (estado.equals(VentanaControl.MENSAJE_NO_ESTA_EJECUTADO)) {
            lblEstadoEjecucion.setBackground(new Color(204, 204, 204));
        }
    }

    /**
     * Muestra un mensaje
     *
     * @param tipo
     * @param titulo
     * @param mensaje
     */
    public void mostrarMensaje(int tipo, String titulo, String mensaje) {
        JOptionPane.showMessageDialog(this.getParent(), mensaje, titulo, tipo);
    }

    private void emitirInforme() {
        prepararEmision();
        try{
            gestor.emitirInformeControl();
        }catch(Exception e){
            concluirEmision(JOptionPane.ERROR_MESSAGE, "<HTML><b>Error al generar el informe:</b>\n" + e.getMessage());
        }
        concluirEmision(JOptionPane.INFORMATION_MESSAGE, "<HTML>Se concluyo con <b>éxito</b> la generación del Informe");
    }
    
    protected void prepararEmision() {
        btnEmitir.setEnabled(false);
    }
    
    protected void concluirEmision(int tipoMensaje,String mensaje) {
        btnEmitir.setEnabled(true);
        mostrarMensaje(tipoMensaje,"Atencion!", mensaje);
    }   

    private void initGraficos() {
        
        initGraficoControlMontos();
        initGraficoControlHerramientas();
        initGraficoGastosVarios();
        initGraficoAlquileresCompras();
        
        initGraficoTortaCotizacion();
        initGraficoTortaEjecucion();
        
    }

    private void initGraficoControlMontos() {
        List<PedidoObra> pos = new ArrayList<PedidoObra>();
        pos.add(gestor.getPedidoObraActual());
        GraficoMontosControlObra graficoComparativaCostos = new GraficoMontosControlObra(pos);
        JFreeChart chart = graficoComparativaCostos.createGraph();
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(200, 100));
        panelGraficoControlMontos.add(chartPanel, BorderLayout.CENTER);
    }
    
    private void initGraficoControlHerramientas() {
        List<PedidoObra> pos = new ArrayList<PedidoObra>();
        pos.add(gestor.getPedidoObraActual());
        GraficoHerramientasControlObra graficoHerramienta = new GraficoHerramientasControlObra(pos);
        JFreeChart chart = graficoHerramienta.createGraph();
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(200, 100));
        panelGraficoHerramientas.add(chartPanel, BorderLayout.CENTER);
    }    

    private void initGraficoGastosVarios() {
        List<PedidoObra> pos = new ArrayList<PedidoObra>();
        pos.add(gestor.getPedidoObraActual());
        GraficoGastosVariosControlObra grafico = new GraficoGastosVariosControlObra(pos);
        JFreeChart chart = grafico.createGraph();
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(200, 100));
        panelGraficoGastosVarios.add(chartPanel, BorderLayout.CENTER);
    }

    private void initGraficoAlquileresCompras() {
        List<PedidoObra> pos = new ArrayList<PedidoObra>();
        pos.add(gestor.getPedidoObraActual());
        GraficoAlquileresComprasControlObra grafico = new GraficoAlquileresComprasControlObra(pos);
        JFreeChart chart = grafico.createGraph();
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(200, 100));
        panelGraficoAlquileresCompras.add(chartPanel, BorderLayout.CENTER);
    }

    private void initGraficoTortaEjecucion() {
        
        GraficoTortaRecursosEjecucion tortaEjec = new GraficoTortaRecursosEjecucion(gestor.getPedidoObraActual());
        JFreeChart chart = tortaEjec.createGraph();
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(200, 100));
        panelGraficoTortaEjecucion.add(chartPanel,BorderLayout.CENTER);
        
    }
    
    private void initGraficoTortaCotizacion() {
        
        GraficoTortaRecursosCotizacion tortaEjec = new GraficoTortaRecursosCotizacion(gestor.getPedidoObraActual());
        JFreeChart chart = tortaEjec.createGraph();
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(200, 100));
        panelGraficoTortaCotizacion.add(chartPanel,BorderLayout.CENTER);
        
    }    
    
}
